package com.service.impl;

import com.bean.entity.StudentCommunication;
import com.bean.pojo.PageAssistant;
import com.bean.vo.StudentCommunicationVo;
import com.dao.StudentCommunicationMapper;
import com.service.StudentCommunicationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * User: 刘文雄
 * Date:2022/3/30 15:58
 *  学生交流表
 */
@Service
public class StudentCommunicationServiceImpl implements StudentCommunicationService {

    @Autowired
    private StudentCommunicationMapper studentCommunicationMapper;

    @Override
    public int save(StudentCommunication t) throws Exception {
        int insert = studentCommunicationMapper.insert(t);
        if (insert==1) return 1;
        throw new Exception("新增学生交流信息失败");
    }
    @Override
    public int remove(StudentCommunication t) throws Exception {
        int delete = studentCommunicationMapper.delete(t);
        if (delete==1) return 1;
        throw new Exception("删除学生交流信息失败");
    }
    @Override
    public int modify(StudentCommunication t) throws Exception {
        int update = studentCommunicationMapper.update(t);
        if (update==1) return 1;
        throw new Exception("修改学生交流信息失败");
    }
    @Override
    public StudentCommunicationVo unique(StudentCommunication t) throws Exception {
        List<StudentCommunicationVo> studentCommunicationVoList = studentCommunicationMapper.select(t);
        if (studentCommunicationVoList.size() !=1)
            throw new Exception("没有相关信息");
        return studentCommunicationVoList.get(0);
    }
    @Override
    public List<StudentCommunicationVo> query(StudentCommunication t) throws Exception {
        List<StudentCommunicationVo> studentCommunicationVoList = studentCommunicationMapper.select(t);
        if (studentCommunicationVoList.size() !=1)
            throw new Exception("没有相关信息");
        return studentCommunicationVoList;
    }
    @Override
    public PageAssistant<StudentCommunicationVo> queryByPage(Map<String, Object> map, PageAssistant<StudentCommunicationVo> pa) {

        //查询并设置总记录数
        pa.setCount(studentCommunicationMapper.selectCount(map));
        //添加分页参数
        map.put("startCode", pa.getStartCode());
        map.put("pageSize", pa.getPageSize());

        //查询并设置页面内容
        pa.setItems(studentCommunicationMapper.selectByPage(map));
        return pa;
    }
}
